<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel header="Search Bills" >
                        <f:facet name="header" >                          
                            <h:outputLabel value="Store Variant Adjustment Report  "/>                         
                            <h:panelGrid columns="5" >
                                <h:outputLabel value="From Date"/>
                                <p:calendar styleClass="dateTimePicker" id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                                </p:calendar>
                                <h:outputLabel value="To Date"/>
                                <p:calendar id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                                </p:calendar>
                                <p:commandButton id="btnSearch" ajax="false" value="Search" action="#{searchController.createVariantReportSearch}"/>
                                <p:spacer height="30"/><h:outputLabel/><h:outputLabel/><h:outputLabel/><h:outputLabel/>

                                <h:outputLabel value="Bill No"/>
                                <h:outputLabel value="Department Name"/>   
                                <h:outputLabel value="Category"/>
                                <h:outputLabel/><h:outputLabel/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.department}" />
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.category}" />
                                <h:outputLabel/><h:outputLabel/>
                            </h:panelGrid>


                        </f:facet>

                        <p:dataTable rowIndexVar="i" id="tblBills" value="#{searchController.bills}" var="bill"   >

                            <p:column headerText="No" styleClass="alignTop">
                                <h:outputLabel value="#{i+1}"/>
                            </p:column>

                            <p:column headerText="Report ID">                     
                                <h:outputLabel  value="#{bill.deptId}">                              
                                </h:outputLabel>                        
                            </p:column>

                            <p:column headerText="Reported At">                      
                                <h:outputLabel  value="#{bill.createdAt}">
                                    <f:convertDateTime pattern="dd MM yy HH:mm:ss a"/>
                                </h:outputLabel>                        
                            </p:column>

                            <p:column headerText="Department" >                      
                                #{bill.department.name}                         
                            </p:column> 

                            <p:column headerText="Category" >                      
                                #{bill.category.name}                         
                            </p:column> 

                            <p:column headerText="Reported Person">
                                #{bill.creater.webUserPerson.nameWithTitle}
                            </p:column>

                            <p:column headerText="View Before Stock">
                                
                                <p:commandButton ajax="false" value="View Before Stock" 
                                                action="store_variant_category_stock_by_item"  >
                                    <f:setPropertyActionListener target="#{reportsStockVariant.department}" value="#{bill.department}"/>
                                    <f:setPropertyActionListener target="#{reportsStockVariant.category}" value="#{bill.category}"/>
                                    <f:setPropertyActionListener target="#{reportsStockVariant.recordedBill}" value="#{bill}"/>       
                                    <f:setPropertyActionListener target="#{reportsStockVariant.records}" value="#{bill.stockVarientBillItems}"/>       
                                </p:commandButton>
                            </p:column>

                            <p:column headerText="Save After Stock">
                              
                                <p:commandButton ajax="false" value="Save After Stock" 
                                                action="store_variant_category_stock_by_item_after" actionListener="#{reportsStockVariant.fillCategoryStocksAfter()}">
                                    <f:setPropertyActionListener target="#{reportsStockVariant.department}" value="#{bill.department}"/>
                                    <f:setPropertyActionListener target="#{reportsStockVariant.category}" value="#{bill.category}"/>
                                    <f:setPropertyActionListener target="#{reportsStockVariant.recordedBill}" value="#{bill}"/>       
                                    <f:setPropertyActionListener target="#{reportsStockVariant.recordedBillAfter}" value="#{null}"/>       
                                    <f:setPropertyActionListener target="#{reportsStockVariant.records}" value="#{bill.stockVarientBillItems}"/>                         
                                </p:commandButton>
                            </p:column>

                            <p:column>
                                <p:dataTable value="#{bill.forwardReferenceBills}" var="f">
                                    <p:column >
                                        #{f.deptId}
                                    </p:column>
                                    <p:column headerText="Reported At">                      
                                        <h:outputLabel  value="#{f.createdAt}">
                                            <f:convertDateTime pattern="dd MM yy HH:mm:ss a"/>
                                        </h:outputLabel>                        
                                    </p:column>
                                    <p:column headerText="Reported Person">
                                        #{f.creater.webUserPerson.nameWithTitle}
                                    </p:column>
                                    <p:column headerText="View After Stock">
                                       
                                        <p:commandButton ajax="false" value="View After Stock" 
                                                        action="store_variant_category_stock_by_item_after"  >
                                            <f:setPropertyActionListener target="#{reportsStockVariant.department}" value="#{f.department}"/>
                                            <f:setPropertyActionListener target="#{reportsStockVariant.category}" value="#{f.category}"/>
                                            <f:setPropertyActionListener target="#{reportsStockVariant.recordedBillAfter}" value="#{f}"/>       
                                            <f:setPropertyActionListener target="#{reportsStockVariant.recordsAfter}" value="#{f.stockVarientBillItems}"/>       
                                        </p:commandButton>
                                    </p:column>
                                </p:dataTable>
                            </p:column>

                        </p:dataTable>


                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
